<template>
  <div>
    <el-dialog :visible.sync="addOpen" title="生成数据" width="500px" @close="dialogClose" append-to-body>
       <el-form ref="form" label-width="80px" v-if="row != null">
         <el-form-item label="收货编号">
           {{row.collectId}}
         </el-form-item>
         <el-form-item label="供应商">
           {{supFormat(row)}}
         </el-form-item>
         <el-form-item label="数量">
           {{row.collectNum}}
         </el-form-item>
         <el-form-item label="绿色回收">
           <el-tag>
             {{row.hasGreen === 'y' ? '是':'否'}}
           </el-tag>
         </el-form-item>
         <el-form-item label="初始步骤">
           <el-radio-group v-model="step">
             <el-radio label="y">待验机</el-radio>
             <el-radio label="r">待入库</el-radio>
           </el-radio-group>
         </el-form-item>
       </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogClose">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {createGoodsList} from "@/api/recovery/collect";

export default {
  name: "collect_add",
  props: {
    open: Boolean,
    row: Object,
    supFormat: Function
  },
  data(){
    return {
      addOpen: this.open,
      step: 'y',
    }
  },
  watch: {
    row(n, o) {
      this.row = n;
    },
    open(n, o) {
      this.open = n;
      this.addOpen = this.open;
    }
  },
  methods: {
    dialogClose() {
      this.addOpen = false;
      this.$emit("close");
    },
    submitForm() {
      if(this.row.hasGreen === 'y') {
        if(this.step !== 'r') {
          this.msgError("绿色回收只能选着待入库！")
          return
        }
      }
      const params = {
        collectId: this.row.collectId,
        params: {
          step: this.step
        }
      }
      createGoodsList(params).then(res => {
        this.msgSuccess("操作成功！")
        this.dialogClose();
        this.$emit("flush")
      })
    },
  }
}
</script>

<style scoped>

</style>
